package org.huang.spock.spring.service;

import org.huang.spock.spring.component.LockManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.locks.Lock;

@Service
public class LockService {
    @Autowired
    private LockManage lockManage;

    public String testLockMock(String key){
        Lock lock = lockManage.getLock(key);
        if (!lock.tryLock()) {
            return "Error";
        }
        try {
            return "Success";
        } finally {
            lock.unlock();
        }
    }
}
